﻿<?php
include("../includes/db_connect.php");
session_start();	
$messageQuery = mysqli_query($db, "SELECT * FROM news ORDER BY date DESC");
while($message = $messageQuery->fetch_assoc()) {
	$userQuery = mysqli_query($db, "SELECT username, firstname, lastname FROM users WHERE id={$message["authorId"]} LIMIT 1");
	$user = $userQuery->fetch_assoc();
	echo "<div style=\"margin-bottom:20px;\">";
	echo "<div style=\"border-bottom:1px solid #A8A8A8; padding: 10px;\">";
	echo "<div class=\"title\"><p style=\"margin:0; padding:0\"><b>{$message["title"]}</b></p></div>";
	echo "<div class=\"message\" style=\"border-top:1px solid #A8A8A8; display:none; width:100%; padding:15px;\">";
	echo "<p style=\"margin:0; padding:0\"><b>Skribent: </b>{$user["username"]} ({$user["firstname"]} {$user["lastname"]})</p><br>";
	echo $message["text"];
	echo "</div>";
	echo "</div>";
	echo "</div>";	
}

?>
<script src="script/jquery-1.11.1.min.js"></script>
<script>
$('div.title').click(function (e) {
	$(this).parent().children('div.message').toggle(300);
	this.css
});

$('div.title').hover(function(){
  $("div.title").css("cursor", "pointer");
});
</script>